﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DevFx.FrameWork;

namespace DevFx.Web.Code
{
    public class BasePage : System.Web.UI.Page
	{
        /// <summary>
        /// 排序方法使用（Push一个排序列名）
        /// </summary>
        /// <param name="SortField"></param>
        /// <param name="pager"></param>
        public void PushSort(string SortField,PagerCondition pager)
        {
            SortCondition sort = new SortCondition();
            sort.SortField = SortField;
            if (pager.GridDirection == "ASC")
            {
                sort.SortDirection = FrameWork.SortDirection.DESC;
                pager.GridDirection = "DESC";
            }
            else
            {
                sort.SortDirection = FrameWork.SortDirection.ASC;
                pager.GridDirection = "ASC";
            }
            pager.SortConditions.Push(sort);
        }
        #region 属性
        /// <summary>
        /// 用户ID
        /// </summary>
        public Guid UserID
        {
            get { return Guid.Empty; }
        }
        /// <summary>
        /// 是否新增页面
        /// </summary>
        public bool IsAdd
        {
            get
            {
                if (string.IsNullOrEmpty(Request.QueryString["flag"]))
                {
                    return false;
                }
                else
                {
                    if (Request.QueryString["flag"].ToString().Trim() == "1")
                    {
                        return true;
                    }
                }

                return false;
            }
        }
        /// <summary>
        /// 是否编辑页面
        /// </summary>
        public bool IsEdit
        {
            get
            {
                if (string.IsNullOrEmpty(Request.QueryString["flag"]))
                {
                    return false;
                }
                else
                {
                    if (Request.QueryString["flag"].ToString().Trim() == "2")
                    {
                        return true;
                    }
                }
                
                return false;
            }
        }
        /// <summary>
        /// 是否查看页面
        /// </summary>
        public bool IsView
        {
            get
            {
                if (string.IsNullOrEmpty(Request.QueryString["flag"]))
                {
                    return false;
                }
                else
                {
                    if (Request.QueryString["flag"].ToString().Trim() == "3")
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        /// <summary>
        /// EditID
        /// </summary>
        public Guid EditID
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    return new Guid(Request.QueryString["id"].ToString());
                }
                return Guid.Empty;
            }
        }

        #region 方法
        public void BasePagerInit(PagerCondition pager)
        {
            pager.IsPaging = false;
            //判断总页数与当前页数
            if (pager.CurrentPage > pager.PageCount)
            {
                pager.CurrentPage = pager.PageCount;
            }
            if (pager.SortConditions.Count < 1)
            {
                SortCondition item = new SortCondition();
                item.SortDirection = FrameWork.SortDirection.ASC;
                item.SortField = "CreateDate";
                pager.SortConditions.Push(item);
            }
        }
        public void BasePagerInit(PagerCondition pager, string SortName)
        {
            pager.IsPaging = false;
            //判断总页数与当前页数
            if (pager.CurrentPage > pager.PageCount)
            {
                pager.CurrentPage = pager.PageCount;
            }
            if (pager.SortConditions.Count < 1)
            {
                SortCondition item = new SortCondition();
                item.SortDirection = FrameWork.SortDirection.ASC;
                item.SortField = SortName;
                pager.SortConditions.Push(item);
            }
        }        
        #endregion
        
        #endregion
	}
}